using UnityEngine;
using System.Collections;

public class csBulletCtrl : csBulletAttributes 
{
//============== Input Data ==============	
#region InputData
	public float 		FlySpeed 		= 10.0f;	//Fly speed. Units = pixel
	public Vector3		ShipMoveDirect 	= Vector3.up;
	public string[]		DestroyTag;					//Tag name which is touched that will destroy bullet.
	public string[]		ShowExplosionFXTag;			//Tag name which is touched that will destroy bullet and show Explosion FX.
	public GameObject 	ExplosionFX;				//Explosion Effect
	
#endregion
	
//============== Data Member ==============	
#region DataMember
	protected int FrameCounter = 0;
#endregion
	
//============== Member Function ==============
#region MemberFunc
	protected void Flying()
	{
		this.transform.Translate(ShipMoveDirect * FlySpeed);
	}
#endregion	
		
//============== System Function ==============		
#region SystemFunc	
	// Use this for initialization
	void Start () 
	{
	}
	
	// Update is called once per frame
	void Update () 
	{
		this.Flying();	
	}
	
	//Collision
	void OnTriggerEnter(Collider ColiObj)
	{
	//Show ExplosionFX when touch ???
		foreach(string TargetTag in this.ShowExplosionFXTag)
		{
			if( ColiObj.tag == TargetTag )	{
				Instantiate(this.ExplosionFX, this.gameObject.transform.position, this.gameObject.transform.rotation);
				break;
			}
		}
		
	//Destroy by Who
		foreach(string strDestroyTag in this.DestroyTag)
		{
			if( ColiObj.gameObject.tag == strDestroyTag ) 
			{	
/*		Just Enemy and its slaver will show explosion FX.
				if(ColiObj.gameObject.tag == "Enemy")
				{
				//Show Explosion Effect	
					Instantiate(this.ExplosionFX, this.gameObject.transform.position, this.gameObject.transform.rotation);
				//Destory Self
					Destroy(this.gameObject);					
				}else if( ColiObj.gameObject.tag == "DeathZone" || ColiObj.tag == "EnemyDeathZone") {
				//Destory Self
					Destroy(this.gameObject);										
				}
*/
				if(ColiObj.tag == "Player")
				{
					if(this.tag != "EnemyBullets")
						return;
					
					csShipCtrl Player = ColiObj.GetComponent<csShipCtrl>();
					if(Player)
					{
						if(!Player.IsPlaying())
						   continue;
					}
				}	//End of if(ColiObj.tag == "Player")
				
			//Destory Self
				Destroy(this.gameObject);																		
				
				//Player needs to control the explosion
				break;
			}
		}
	}
#endregion
}
